#!/bin/bash

title()       { grep "^title: " $f | sed -e "s/^title: //"; }
date()        { grep "^date: "  $f | sed -e "s/^date: //";  }
description() { perl -p0e 's/^---[\s\S]*?\.\.\.\n\n//' $f |
                perl -p0e 's/(\.|\?|\!)( |\n)(.|\n)*/.../g'; }

cat blog-list.md > blog/index.md

find blog/*.md -exec ./redate.sh \{} \;

cd blog

for f in $(ls -1t *.md | sed -e s-.*index.md--); do
    touch -d "$(date)" $f
    echo -e "[$(title)](${f%.md}.html){.title}\n" >> index.md
    echo -e "$(description)\n"                    >> index.md
done

cd ..

for f in $(find . -type f -name "*.md"); do
    pandoc $f --filter pandoc-citeproc --css style.css -T "Alyssa Rosenzweig" \
           license.md -s --smart > ${f%.md}.html
done
